package com.aspose.cells;

import java.security.MessageDigest;

class zsv {
   byte[] a = new byte[20];
   private zvh d;
   MessageDigest b;
   int c = 128;
   private byte[] e = new byte[]{-13, 37, 115, -73, -5, -80, 94, 112, -52, 43, -38, 72, -22, -74, 124, -98};
   private byte[] f = new byte[]{-122, -39, -127, 105, -11, -77, -126, 51, 86, -80, 21, -69, 51, -7, -33, -53};
   private byte[] g = new byte[]{26, -109, 86, 19, 26, 94, -86, -48, -38, 36, -71, -78, 23, -81, -73, -51};
   private byte[] h = new byte[]{-50, -111, 10, 82, 17, -44, -1, 18, 74, -12, 35, 45, -37, 29, -58, -5, -72, -122, 111, -93, -88, -65, 39, 29, -55, -26, 33, -45, 120, -50, 24, -15};
   private byte[] i = new byte[]{-57, -104, -55, -34, -51, -97, -53, -72, 39, 88, 114, 127, -18, -8, -26, -25};

   zsv(zvh var1, byte[] var2, byte[] var3) throws Exception {
      this.d = var1;
      com.aspose.cells.b.a.d.zh var4 = new com.aspose.cells.b.a.d.zh(var2, 8, var2.length - 8);
      zcfk var5 = zass.a((com.aspose.cells.b.a.d.zm)var4);
      zcfl var6 = (zcfl)var5.j().a(0);
      zcfl var7 = (zcfl)var6.j().a("keyData");
      zcfg var8 = var7.c("saltValue");
      this.e = com.aspose.cells.b.a.ze.b(var8.a());
      zcfg var9 = var7.c("keyBits");
      if (var9 != null) {
         this.c = com.aspose.cells.b.a.zo.a(var9.a(), com.aspose.cells.b.a.c.za.b());
      }

      String var10 = "SHA1";
      zcfg var11 = var7.c("hashAlgorithm");
      if (var11 != null) {
         var10 = var11.a();
      }

      zcfl var12 = (zcfl)var6.j().a("keyEncryptors");
      zcfl var13 = null;
      var13 = (zcfl)var12.j().a("keyEncryptor").j().a("encryptedKey");
      if (var13 == null) {
         var13 = (zcfl)var12.j().a("keyEncryptor").j().a("p:encryptedKey");
      }

      zcfg var14 = var13.c("saltValue");
      this.f = com.aspose.cells.b.a.ze.b(var14.a());
      zcfg var15 = var13.c("encryptedVerifierHashInput");
      this.g = com.aspose.cells.b.a.ze.b(var15.a());
      zcfg var16 = var13.c("encryptedVerifierHashValue");
      this.h = com.aspose.cells.b.a.ze.b(var16.a());
      zcfg var17 = var13.c("encryptedKeyValue");
      this.i = com.aspose.cells.b.a.ze.b(var17.a());
      if (var10.equalsIgnoreCase("SHA256")) {
         this.b = MessageDigest.getInstance("SHA-256");
      } else if (var10.equalsIgnoreCase("SHA512")) {
         this.b = MessageDigest.getInstance("SHA-512");
      } else {
         this.b = MessageDigest.getInstance("SHA-1");
      }

      byte[] var18 = new byte[this.f.length + var3.length];
      System.arraycopy(this.f, 0, var18, 0, this.f.length);
      System.arraycopy(var3, 0, var18, this.f.length, var3.length);
      this.a = this.a(this.b, var18);
      byte[] var19 = new byte[this.a.length + 4];

      for(int var20 = 0; var20 < 100000; ++var20) {
         System.arraycopy(com.aspose.cells.b.a.zc.a(var20), 0, var19, 0, 4);
         System.arraycopy(this.a, 0, var19, 4, this.a.length);
         this.a = this.a(this.b, var19);
      }

   }

   private byte[] a(byte[] var1, byte[] var2, byte[] var3) throws Exception {
      byte[] var4 = new byte[]{-2, -89, -46, 118, 59, 75, -98, 121};
      byte[] var5 = new byte[var1.length + var4.length];
      System.arraycopy(var1, 0, var5, 0, var1.length);
      System.arraycopy(var4, 0, var5, var1.length, var4.length);
      byte[] var6 = new byte[this.c / 8];
      System.arraycopy(this.a(this.b, var5), 0, var6, 0, var6.length);
      za var7 = new za("CBC", "ZeroBytePadding", var2, var6);
      byte[] var8 = var7.a(var3);
      return this.a(this.b, var8);
   }

   private byte[] b(byte[] var1, byte[] var2, byte[] var3) throws Exception {
      byte[] var4 = new byte[]{-41, -86, 15, 109, 48, 97, 52, 78};
      byte[] var5 = new byte[var1.length + var4.length];
      System.arraycopy(var1, 0, var5, 0, var1.length);
      System.arraycopy(var4, 0, var5, var1.length, var4.length);
      byte[] var6 = new byte[this.c / 8];
      System.arraycopy(this.a(this.b, var5), 0, var6, 0, var6.length);
      int var7 = (var3.length + 15) / 16 * 16;
      byte[] var8 = new byte[var7];
      byte[] var9 = new byte[var7];
      System.arraycopy(var3, 0, var8, 0, var3.length);
      zb var10 = new zb("CBC", "ZeroBytePadding", var2, var6);
      return var10.a(var8);
   }

   boolean a() throws Exception {
      byte[] var1 = this.a(this.a, this.f, this.g);
      byte[] var2 = this.b(this.a, this.f, var1);
      boolean var3 = true;

      for(int var4 = 0; var4 < var2.length && var4 < this.h.length; ++var4) {
         if (var2[var4] != this.h[var4]) {
            var3 = false;
            break;
         }
      }

      return var3;
   }

   com.aspose.cells.b.a.d.zm b() throws Exception {
      boolean var1 = true;
      byte[] var2 = new byte[this.a.length + 8];
      System.arraycopy(this.a, 0, var2, 0, this.a.length);
      System.arraycopy(new byte[]{20, 110, 11, -25, -85, -84, -48, -42}, 0, var2, this.a.length, 8);
      byte[] var3 = this.a(this.b, var2);
      var2 = new byte[this.c / 8];
      System.arraycopy(var3, 0, var2, 0, var2.length);
      za var4 = new za("CBC", "ZeroBytePadding", this.f, var2);
      byte[] var5 = var4.a(this.i);
      com.aspose.cells.b.a.d.zh var6 = this.d.a().a("EncryptedPackage");
      long var7 = var6.h();
      long var9 = 0L;
      com.aspose.cells.b.a.d.zh var11 = new com.aspose.cells.b.a.d.zh((int)var6.h());
      byte[] var12 = new byte[4096];
      var6.b(8L);
      var2 = new byte[20];
      byte[] var13 = new byte[16];

      int var14;
      try {
         for(; var9 < var7 - 8L; var9 += (long)var14) {
            System.arraycopy(this.e, 0, var2, 0, 16);
            System.arraycopy(com.aspose.cells.b.a.zc.a(var9 / 4096L), 0, var2, 16, 4);
            System.arraycopy(this.a(this.b, var2), 0, var13, 0, 16);
            var14 = var6.a(var12, 0, 4096);
            byte[] var15 = new byte[var14];
            System.arraycopy(var12, 0, var15, 0, var14);
            za var16 = new za("CBC", "ZeroBytePadding", var13, var5);
            byte[] var17 = var16.a(var15);
            var11.b(var17, 0, var17.length > var14 ? var14 : var17.length);
            if (var14 > var17.length) {
               byte[] var18 = new byte[var14 - var17.length];
               var11.b(var18, 0, var18.length);
            }
         }
      } catch (Exception var19) {
         throw new CellsException(6, "unkown excel content!");
      }

      var11.b(0L);
      return var11;
   }

   private byte[] a(MessageDigest var1, byte[] var2) {
      var1.update(var2);
      return var1.digest();
   }

   static boolean a(String var0, String var1, byte[] var2, byte[] var3, int var4) {
      try {
         byte[] var5 = new byte[var0.length() * 2];

         for(int var6 = 0; var6 < var0.length(); ++var6) {
            var5[var6 * 2 + 1] = (byte)(var0.charAt(var6) >> 8);
            var5[var6 * 2] = (byte)(var0.charAt(var6) & 255);
         }

         MessageDigest var13 = null;
         if (!var1.equals("SHA-256") && !var1.equals("SHA-512") && !var1.equals("SHA-1")) {
            return false;
         } else {
            var13 = MessageDigest.getInstance(var1);
            byte[] var7 = new byte[var3.length + var5.length];
            System.arraycopy(var3, 0, var7, 0, var3.length);
            System.arraycopy(var5, 0, var7, var3.length, var5.length);
            byte[] var8 = var13.digest(var7);
            if (var8.length != var2.length) {
               return false;
            } else {
               byte[] var9 = new byte[var8.length + 4];

               for(int var10 = 0; var10 < var4; ++var10) {
                  System.arraycopy(var8, 0, var9, 0, var8.length);
                  System.arraycopy(com.aspose.cells.b.a.zc.a(var10), 0, var9, var8.length, 4);
                  var8 = var13.digest(var9);
               }

               boolean var14 = true;

               for(int var11 = 0; var11 < var8.length; ++var11) {
                  if (var8[var11] != var2[var11]) {
                     var14 = false;
                     break;
                  }
               }

               return var14;
            }
         }
      } catch (Exception var12) {
         return false;
      }
   }
}
